﻿Public Class PersonProfessionDataTemplateSelector
    Inherits DataTemplateSelector

    Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As System.Windows.DependencyObject) As System.Windows.DataTemplate

        If item IsNot Nothing AndAlso TypeOf item Is Person Then
            Dim objPerson As Person = DirectCast(item, Person)

            If objPerson.Profession.Contains("Agent") Then
                Return TryCast(Application.Current.MainWindow.TryFindResource("agentDataTemplate"), DataTemplate)
            Else
                Return TryCast(Application.Current.MainWindow.TryFindResource("nonAgentDataTemplate"), DataTemplate)
            End If

        Else
            Return Nothing
        End If
    End Function

End Class
